#include <stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while (t--)
    {
        int h,m,s;
        double hd,md,t;
        scanf("%d%d%d",&h,&m,&s);
        if (h>12)h-=12;
        md=(m+s/60.0)*6;
        hd=(h+m/60.0+s/3600.0)*30;
        if (md>hd)t=md-hd;
        else t=hd-md;
        if (t>180)t=360-t;
        printf("%d\n",int(t));
    }
    return 0;
}
